<template>
  <Layout>
    <Form ref="form1" :model="form1" :label-width="120">
      <Row class="query-form" style="padding-top: 10px" v-show="!switchFlag">
        <Col span="8">
          <FormItem label="风险类别：">
            <Select filterable v-model="form1.riskType"
                    :label-in-value="true">
              <Option v-for="item in riskTypeArr" :value="item.codingCodeId" :label="item.codingName">
                {{ item.codingName }}
              </Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label="风险识别维度：">
            <Select v-model="form1.rikDiscernName">
              <Option v-for="item in rikDiscernList" :value="item.codingCodeId" :label="item.codingName">
                {{ item.codingName }}
              </Option>
            </Select>
          </FormItem>
        </Col>

        <Col span="8">
          <Button @click="switchQuery(true)" class="ivu-btn-switch" type="text">展开∨</Button>
          <Button @click="reset('0')" class="ivu-btn-reset">重置</Button>
          <Button class="ivu-btn-query" icon="md-search" @click="querys()">查询</Button>
        </Col>
      </Row>
      <Row v-show="switchFlag" class="query-form" style="padding-top: 10px">
        <Col span="8">
          <FormItem label="风险类别：">
            <Select filterable v-model="form1.riskType"
                    :label-in-value="true">
              <Option v-for="item in riskTypeArr" :value="item.codingCodeId" :label="item.codingName">
                {{ item.codingName }}
              </Option>
            </Select>
          </FormItem>
        </Col>

        <Col span="8">
          <FormItem label="风险识别维度：">
            <Select v-model="form1.rikDiscernName">
              <Option v-for="item in rikDiscernList" :value="item.codingCodeId" :label="item.codingName">
                {{ item.codingName }}
              </Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label="风险等级：">
            <Select v-model="rikRanks" multiple style="width:100%">
              <Option v-for="item in rikRankList" :value="item" :key="item">{{ item }}</Option>
            </Select>
          </FormItem>
        </Col>
      </Row>
      <Row v-show="switchFlag" class="query-form">

<!--        <Col span="8">
          <FormItem label="风险状态：">
            <Select v-model="form1.auditState">
              <Option value="0">未上报</Option>
              <Option value="1">审批中</Option>
              <Option value="3">审核驳回</Option>
              <Option value="2">审批通过</Option>
            </Select>
          </FormItem>
        </Col>-->
        <Col span="8">
          <FormItem label="一级风险单元：">
            <Input type="text" v-model="form1.riskUnit"/>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label="二级风险单元：">
            <Input type="text" v-model="form1.riskUnit2"/>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label="三级风险单元：">
            <Input type="text" v-model="form1.riskUnit3"/>
          </FormItem>
        </Col>

      </Row>
      <Row v-show="switchFlag" class="query-form">


        <Col span="8">
          <FormItem label="四级风险单元：">
            <Input type="text" v-model="form1.riskUnit4"/>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label="关注级别：">
            <Select v-model="form1.rank" style="width:100%">
              <Option value="1">集团</Option>
              <Option value="2">二级集团</Option>
              <Option value="3">集团和二级集团</Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label="二级集团：">
            <two-level-org org-code class="w" v-model="form1.twoLevelOrgId"></two-level-org>
          </FormItem>
        </Col>

      </Row>
      <Row v-show="switchFlag" class="query-form">
        <Col span="8" offset="16">
          <Button @click="switchQuery(false)" class="ivu-btn-switch" type="text">收起∧</Button>
          <Button @click="reset('0')" class="ivu-btn-reset">重置</Button>
          <Button class="ivu-btn-query" icon="md-search" @click="querys">查询</Button>
        </Col>
      </Row>
      <Row class="query-form">
        <Col span="24">
          <Button size="large" class="ivu-btn-add" icon="md-add" @click="addInfo">新增</Button>
          <!--          <Button size="large" class="ivu-btn-add" icon="md-add" @click="addByTemp">基于模板新增</Button>-->
          <Button size="large" class="ivu-btn-add" icon="md-cloud-upload" @click="uploadExcel">导入</Button>
          <Button size="large" class="ivu-btn-add" icon="md-cloud-download" :loading="buttonLoading1"
                  @click="downloadMod">导入模版下载
          </Button>
          <!--          <Button size="large" :disabled="reportSelectAll.length<1" :loading="buttonLoading"
                            class="ivu-btn-add" @click="reporting">
                      上报
                    </Button>-->
          <Button size="large" :disabled="reportSelectAll.length<1" :loading="deleteButton"
                  class="ivu-btn-add" @click="batchDelete">
            批量删除
          </Button>
          <Button size="large" :disabled="reportSelectAll.length<1"
                  v-if="hasRole(this.currentUser,'dda573b123f9472d95ba3063b25133f7')"
                  class="ivu-btn-add" @click="rank('1')">
            集团定级
          </Button>
          <Button size="large" :disabled="reportSelectAll.length<1"
                  v-if="hasRole(this.currentUser,'3c74f3e935dd4bb4be32d6c342f28b81')"
                  class="ivu-btn-add" @click="rank('2')">
            二级集团定级
          </Button>
        </Col>
      </Row>
    </Form>
    <Table ref='table' :loading="loading" size="small" :height="tableHeight" class="table" no-data-text="没有查询到相关数据!"
           @on-selection-change="reportSelect"
           highlight-row stripe border :columns="columns1" width="100%" :data="dataTable">
    </Table>
    <Row style="margin-right:10px;">
      <Col span="24">
        <Page :total="pagedata.total" :page-size="pagedata.pageSize" @on-change="pageChange"
              style="float: right" @on-page-size-change="pageSizeChange" :page-size-opts="pageSizeArray"
              show-total show-sizer show-elevator/>
      </Col>
    </Row>

    <Modal :transfer=false v-model="model1" :width=1000 :title="add?'环境氛围风险识别新增':'环境氛围风险识别修改'"
           @on-cancel="onCancel">
      <Form ref='InputData' :model="InputData" :rules="ruleCustom" label-position="top">
        <Row style="line-height: 25px;">
          <Col span='2'>
            <b>基础信息</b>
          </Col>
          <!-- <Col span='6' offset="1">
               <FormItem label='一级风险单元：' prop="riskUnit">
                   &lt;!&ndash;<Input v-model="InputData.saRiskInfo.riskUnit"/>&ndash;&gt;
                   <Select filterable v-model="InputData.saRiskInfo.riskUnit"
                           @on-open-change="openChange"
                           allow-create @on-create="riskUnitAdd">
                       <Option v-for="item in riskUnits" :value="item" :label="item">
                           {{item}}
                       </Option>
                   </Select>

               </FormItem>
           </Col>-->
          <Col span='6' offset="1">
            <FormItem label='一级风险单元：' prop="riskUnit">
              <!--<Input v-model="InputData.saRiskInfo.riskUnit"/>-->
              <cascaderDom ref="riskUnit" @setOrgInfo="setRiskUnit" @setOrgname="setRiskUnitName"
                           :currentOrgId="InputData.saRiskInfo.riskUnit"
                           :currentOrgName="InputData.saRiskInfo.riskUnitName"
                           :orgTree="true"></cascaderDom>

            </FormItem>
          </Col>
          <Col span='6' offset="1">
            <FormItem label='二级风险单元：' prop="riskUnit2">
              <Input v-model="InputData.saRiskInfo.riskUnit2"/>
              <!--                            <Select filterable v-model="InputData.saRiskInfo.riskUnit2"
                                                  :placeholder="InputData.saRiskInfo.riskUnit==null?'一级风险单元不能为空':'请选择'"
                                                  @on-open-change="openChange"
                                                  allow-create @on-create="riskUnit2Add">
                                              <Option v-for="item in riskUnit2s" :value="item" :label="item">
                                                  {{item}}
                                              </Option>
                                          </Select>-->
            </FormItem>
          </Col>
          <Col span='6' offset="1">
            <FormItem label='三级风险单元：' prop="riskUnit3">
              <Input v-model="InputData.saRiskInfo.riskUnit3"/>
              <!--                            <Select filterable v-model="InputData.saRiskInfo.riskUnit3"
                                                  :placeholder="InputData.saRiskInfo.riskUnit2==null?'二级风险单元不能为空':'请选择'"
                                                  @on-open-change="openChange"
                                                  allow-create @on-create="riskUnit3Add">
                                              <Option v-for="item in riskUnit3s" :value="item" :label="item">
                                                  {{item}}
                                              </Option>
                                          </Select>-->
            </FormItem>
          </Col>
          <Col span='6' offset="3">
            <FormItem label='四级风险单元：' prop="riskUnit4">
              <Input v-model="InputData.saRiskInfo.riskUnit4"/>
              <!--                            <Select filterable v-model="InputData.saRiskInfo.riskUnit4"
                                                  :placeholder="InputData.saRiskInfo.riskUnit3==null?'三级风险单元不能为空':'请选择'"
                                                  @on-open-change="openChange"
                                                  allow-create @on-create="riskUnit4Add">
                                              <Option v-for="item in riskUnit4s" :value="item" :label="item">{{item}}</Option>
                                          </Select>-->
            </FormItem>
          </Col>
          <Col span='6' offset="1">
            <FormItem label='风险类别：' prop="riskType">
              <Select filterable v-model="InputData.saRiskInfo.riskType" @on-change="changeSelect"
                      :label-in-value="true">
                <Option v-for="item in riskTypeArr" :value="item.codingCodeId" :label="item.codingName">
                  {{ item.codingName }}
                </Option>
              </Select>
            </FormItem>
          </Col>
          <Col span='6' offset="1">
            <FormItem label='风险识别维度：' prop="rikDiscernName">
              <!--   <Input v-model="InputData.saRiskInfo.rikDiscernName"/>-->
              <Select filterable v-model="InputData.saRiskInfo.rikDiscernId" @on-change="rikDiscernChange"
                      :label-in-value="true">
                <Option v-for="item in rikDiscernList" :value="item.codingCodeId"
                        :label="item.codingName">
                  {{ item.codingName }}
                </Option>
              </Select>
            </FormItem>
          </Col>
          <Col span='20' offset="3">
            <FormItem label='风险描述：' prop="riskDesc">
              <Input v-model="InputData.saRiskInfo.riskDesc" type="textarea"
                     :autosize="{minRows:2,maxRows:5}"/>
            </FormItem>
          </Col>
        </Row>
        <hr style="margin-top: 10px;color: #dcdcdc"/>
        <Row style="line-height: 25px;margin-top: 10px">
          <Col span='2'>
            <b>风险评价</b>
          </Col>
          <Col span='6' offset="1">
            <FormItem label='历史发生概率Q1：' prop="q1">
              <Select v-model="InputData.q1">
                <Option v-for="item in q1List" :value="item.id" :label="item.id">
                  <span> {{ item.id }}</span>
                  <span style="float:right;color:#ccc"> {{ item.q1Name }}</span>
                </Option>
              </Select>
            </FormItem>
          </Col>
          <Col span='6' offset="1">
            <FormItem label='风险承受能力Q2：' prop="q2">
              <Select v-model="InputData.q2">
                <Option v-for="item in q1List" :value="item.id" :label="item.id">
                  <span> {{ item.id }}</span>
                  <span style="float:right;color:#ccc"> {{ item.q2Name }}</span>
                </Option>
              </Select>
            </FormItem>
          </Col>
          <Col span='6' offset="1">
            <FormItem label='死亡损失M1：' prop="m1">
              <Select v-model="InputData.m1">
                <Option v-for="item in q1List" v-show="item.m1Name!=null" :value="item.id"
                        :label="item.id">
                  <span> {{ item.id }}</span>
                  <span style="float:right;color:#ccc"> {{ item.m1Name }}</span>
                </Option>
              </Select>
            </FormItem>
          </Col>
          <Col span='6' offset="3">
            <FormItem label='重伤损失M2：' prop="m2">
              <Select v-model="InputData.m2">
                <Option v-for="item in q1List" :value="item.id" :label="item.id">
                  <span> {{ item.id }}</span>
                  <span style="float:right;color:#ccc"> {{ item.m2Name }}</span>
                </Option>
              </Select>
            </FormItem>
          </Col>
          <Col span='6' offset="1">
            <FormItem label='经济损失E1：' prop="e1">
              <Select v-model="InputData.e1">
                <Option v-for="item in q1List" :value="item.id" :label="item.id">
                  <span> {{ item.id }}</span>
                  <span style="float:right;color:#ccc"> {{ item.e1Name }}</span>
                </Option>
              </Select>
            </FormItem>
          </Col>
          <Col span='6' offset="1">
            <FormItem label='周边敏感目标影响人数S1：' prop="s1">
              <Select v-model="InputData.s1">
                <Option v-for="item in q1List" :value="item.id" :label="item.id">
                  <span> {{ item.id }}</span>
                  <span style="float:right;color:#ccc"> {{ item.s1Name }}</span>
                </Option>
              </Select>
            </FormItem>
          </Col>
        </Row>
        <Row style="line-height: 25px">
          <Col span='6' offset="3">
            <FormItem label='社会关注度S2：' prop="s2">
              <Select v-model="InputData.s2">
                <Option v-for="item in q1List" :value="item.id" :label="item.id">
                  <span> {{ item.id }}</span>
                  <span style="float:right;color:#ccc"> {{ item.s2Name }}</span>
                </Option>
              </Select>
            </FormItem>
          </Col>
        </Row>
        <Row style="line-height: 25px;margin-top: 10px">
          <Col span='6' offset="3">
            <span>可能性计算：{{ passibleCal }}</span>
          </Col>
          <Col span='6' offset="1">
            <span>严重性计算：{{ InputData.severityCal }}</span>
          </Col>
          <Col span='6' offset="1">
            <span>风险等级R：{{ InputData.rikRankName }}</span>
          </Col>
        </Row>
        <Row style="line-height: 25px;margin-top: 10px">
          <Col span='6' offset="3">
            <span>可能性值：{{ passibleCal }}</span>
          </Col>
          <Col span='6' offset="1">
            <span>严重性值：{{ InputData.severityVal }}</span>
          </Col>
          <Col span='6' offset="1">
                        <span>风险警示色：
                            <span v-if="InputData.rikColor=='红'" style="color: red">{{ InputData.rikColor }}</span>
                            <span v-else-if="InputData.rikColor=='橙'"
                                  style="color: orange">{{ InputData.rikColor }}</span>
                            <span v-else-if="InputData.rikColor=='黄'"
                                  style="color: #FDD835">{{ InputData.rikColor }}</span>
                            <span v-else-if="InputData.rikColor=='蓝'"
                                  style="color: blue">{{ InputData.rikColor }}</span>
                            <span v-else style="color: white">{{ InputData.rikColor }}</span>
                        </span>
          </Col>
        </Row>
        <hr style="margin-top: 10px;color: #dcdcdc"/>
        <Row style="line-height: 25px;margin-top: 10px">
          <Col span='2'>
            <b>风险管控</b>
          </Col>
          <Col span='6' offset="1">
            <FormItem label='风险防范措施(技术、管理、教育)：' prop="manageMeasure">
              <Input v-model="InputData.saRiskManage.manageMeasure"/>
            </FormItem>
          </Col>
          <Col span='6' offset="1">
            <FormItem label='应急措施(救治、处置)：' prop="emerMearsure">
              <Input v-model="InputData.saRiskManage.emerMearsure"/>
            </FormItem>
          </Col>
          <Col span='6' offset="1">
            <FormItem label='责任部门：' prop="dutyOrgName"><!-- dutyOrgId -->
              <Input v-model="InputData.saRiskManage.dutyOrgName"/>
              <!--   <cascaderDom ref="childOrg" @setOrgInfo="setOrgId" @setOrgname="setOrgName"
                              :currentOrgId="InputData.saRiskManage.dutyOrgId"
                              :currentOrgName="InputData.saRiskManage.dutyOrgName"
                              :orgTree="true"></cascaderDom>-->
            </FormItem>
          </Col>
          <Col span='6' offset="3">
            <FormItem label='责任人：' prop="dutyPersonName"><!--dutyPersonId-->
              <!--  <cascaderDom ref="childUser1" @setOrgInfo="setUserId" @setOrgname="setUserName"
                             :currentOrgId="InputData.saRiskManage.dutyPersonId"
                             :currentOrgName="InputData.saRiskManage.dutyPersonName">
                </cascaderDom>-->
              <Input v-model="InputData.saRiskManage.dutyPersonName"/>
            </FormItem>
          </Col>
          <Col span='6' offset="1">
            <FormItem label='关注层面：' prop="focusAspectId">
              <Select v-model="InputData.saRiskManage.focusAspectId" @on-change="focusAspectChange"
                      :label-in-value="true">
                <Option v-for="item in focusAspectList" :value="item.codingCodeId"
                        :label="item.codingName">
                  {{ item.codingName }}
                </Option>
              </Select>
            </FormItem>
          </Col>
          <Col span='6' offset="1">
            <FormItem label='关注周期：' prop="focusCycleId">
              <Select v-model="InputData.saRiskManage.focusCycleId" @on-change="focusCycleChange"
                      :label-in-value="true">
                <Option v-for="item in focusCycleList" :value="item.codingCodeId"
                        :label="item.codingName">
                  {{ item.codingName }}
                </Option>
              </Select>
            </FormItem>
          </Col>
          <!--          <Col span='6' offset="3">
                      <FormItem label='审核人：' prop="checker">
                        &lt;!&ndash;<Input v-model="InputData.saRiskAssess.checker"/>&ndash;&gt;
                        &lt;!&ndash;  <cascaderDom ref="childUser" @setOrgInfo="setUserId1" @setOrgname="setUserName1"
                                       :currentOrgId="InputData.saRiskAssess.checker"
                                       :currentOrgName="InputData.saRiskAssess.checkerName">

                          </cascaderDom>&ndash;&gt;
                        <Select
                            v-model="InputData.saRiskAssess.checker"
                            filterable
                            :remote-method="remoteMethod1"
                            :loading="loading1">
                          <Option v-for="(option, index) in options1" :value="option.userId"
                                  :label="option.userName" :key="index">
                            <span>{{ option.userName }}</span>
                            <span style="float:right;color:#ccc">{{ option.orgInfo.orgName }}</span>
                          </Option>
                        </Select>
                      </FormItem>
                    </Col>-->
          <Col span='6' offset="3">
            <FormItem label='录入人：'>
              {{ InputData.saRiskManage.recorder }}
            </FormItem>
          </Col>
          <Col span='6' offset="1">
            <FormItem label='录入时间：'>
              {{ InputData.saRiskManage.recordeTime }}
            </FormItem>
          </Col>
        </Row>
        <!-- <Row type="flex" justify="space-around" class="code-row-bg">
             <Col span="23">
                 <FormItem>
                     <Button class='ivu-btn-save' :loading="buttonLoading||InputData._disabled"
                             @click="submit('InputData')">确定
                     </Button>
                     <Button class='ivu-btn-cancel' @click="onCancel">取消</Button>
                 </FormItem>
             </Col>
         </Row>-->
      </Form>
      <div slot="footer">
        <Button class='ivu-btn-save' :disabled="InputData._disabled" :loading="buttonLoading"
                @click="submit('InputData')">确定
        </Button>
        <Button class='ivu-btn-cancel' @click="onCancel">取消</Button>
      </div>
    </Modal>

    <Modal v-model="model2" :width=800 footer-hide title="预置风险">
      <Form ref="pageModel2" :model="pageModel2" :label-width="120">
        <Row class="query-form">
          <!--<Col span="8">
              <FormItem label="风险名称：">
                  <Input type="text" v-model="pageModel2.hazardFactor"></Input>
              </FormItem>
          </Col>-->
          <Col span="8">
            <FormItem label="风险等级：">
              <Select v-model="rikRanks" multiple style="width:100%">
                <Option v-for="item in rikRankList" :value="item" :key="item">{{ item }}</Option>
              </Select>
              <!--<Input type="text" v-model="pageModel2.rikRankId"/>-->
            </FormItem>
          </Col>
          <Col span="8" offset="8">
            <Button @click="reset('1')" class="ivu-btn-reset">重置</Button>
            <Button class="ivu-btn-query" icon="md-search" @click="addByTemp()">查询</Button>
          </Col>
        </Row>
        <Row>
          <Col span="24">
            <Table height="300" no-data-text="没有查询到相关数据!" @on-row-dblclick="danxuan" size="small"
                   :loading="loading"
                   highlight-row stripe border :columns="columns2" width="100%" :data="riskPreset">
            </Table>
          </Col>
        </Row>
        <Row style="margin-right:10px;">
          <Col span="24">
            <Page :total="pageModel2.total" :page-size="pageModel2.pageSize" @on-change="pageChange1"
                  style="float: right" @on-page-size-change="pageSizeChange1"
                  :page-size-opts="pageSizeArray"
                  show-total show-sizer show-elevator/>
          </Col>
        </Row>
      </Form>
      <!-- <div slot="footer">
           &lt;!&ndash;<Button type="text" @click="model2=false,buttonLoading=false">取消</Button>&ndash;&gt;
           &lt;!&ndash;<Button    :disabled="buttonLoading" @click="baocun">确定</Button>&ndash;&gt;
       </div>-->
    </Modal>

    <Modal :transfer=false v-model="model3" :width=1000 title="环境氛围风险">
      <Form :model="InputData" label-position="top">
        <environmentalRiskApproval ref="environmentalRiskApproval"
                                   :InputData="InputData"></environmentalRiskApproval>
        <!-- <Row type="flex" justify="space-around" class="code-row-bg">
             <Col span="23">
                 <FormItem>
                     <Button class='ivu-btn-save' @click="model3=false">关闭</Button>
                 </FormItem>
             </Col>
         </Row>-->
      </Form>
      <div slot="footer">
        <Button class='ivu-btn-save' @click="model3=false">关闭</Button>
      </div>
    </Modal>
    <Modal :transfer=false v-model="model4" :width=800 title="环境氛围风险导入">
      <Form ref="dataToView" :model="dataToView" :rules="uploadCustom" label-position="top">
        <Row type="flex" justify="center" class="code-row-bg">
          <Col span="23">
            <FormItem label="一级风险单元：" prop="riskUnit">
              <cascaderDom ref="trainOrg" @setOrgInfo="setRiskUnitId" @setOrgname="setRiskUnitNames"
                           :currentOrgId="dataToView.riskUnit" :currentOrgName="dataToView.riskUnitName"
                           :orgTree="true"></cascaderDom>
            </FormItem>
          </Col>
        </Row>

        <Row type="flex" justify="center" class="code-row-bg">
          <Col span="23">
            <FormItem label="附件上传：" prop="file">
              <div>
                <Upload ref="upload"
                        :before-upload="beforeUpload"
                        :show-upload-list="true"
                        :max-size="10240"
                        multiple
                        accept=".xlsx"
                        :format="['xlsx','xls']"
                        type="drag"
                        :action="fileUrl">
                  <div style="padding: 10px">
                    <Icon type="ios-cloud-upload" size="45" style="color: #3399ff"></Icon>
                    <p>点击将文件拖拽到这里上传</p>
                    <span style="font-size:8px;color: #797a64">支持扩展名：.xlsx .xls...</span>
                  </div>
                </Upload>
              </div>
              <div v-if="dataToView.file">
                <p>{{ dataToView.file.name }}</p>
              </div>

            </FormItem>
          </Col>
        </Row>
        <Row type="flex" justify="center" class="code-row-bg">
          <Col span="23">
            <div class="hint">
              <p>导入需知：</p>
              <p>1、导入时会先让选择一级单元（即单位全称），因此模板中不再需要一级单元，直接从二级单元开始自定义。</p>
              <p>2、每一行、每一列都不能合并单元格，每个单元层级都需要取消合并单元格，然后每一行都填充上内容。</p>
              <p>3、关注层面根据目前的设计只能填写“工段”“车间”“班组”“岗位”“项目”“部门”“公司”，关注周期只能填写 “每班”“每天”“每周”“每旬”“每月”“每半月”“每季”“每半年”“每年”“每次” 。</p>
              <p>4、导入方法：将点、线、面、体4页拆分为4个文档在不同风险页签下分别导入。点击对应的风险类别页签，点击“导入”，选择单位（即一级单元），上传文件即可。</p>
            </div>
          </Col>
        </Row>
      </Form>
      <div slot="footer">
        <Button class='ivu-btn-save' :loading="uploadButton" @click="uploadSubmit('dataToView')">确定</Button>
        <Button class='ivu-btn-cancel' @click="uploadcancel">取消</Button>
      </div>
    </Modal>
  </Layout>
</template>

<script>
import {Api} from '../../../../api/index.js'
import {sessionStorage} from '../../../../common/cacheUtils.js';
import cascaderDom from '../../../../components/cascader-dom.vue';
import environmentalRiskApproval from '../riskApproval/environmentalRiskApproval.vue'
import {hasRole} from '@/components/pageCommonFunction.js'

export default {
  // props:['riskUnitsAll'],
  components: {cascaderDom, environmentalRiskApproval},
  name: "environmentalRisk",//环境氛围风险
  data() {
    return {
      uploadButton: false,
      deleteButton: false,
      uploadCustom: {
        riskUnit: [{
          validator: (rule, value, callback) => {
            if (this.dataToView.riskUnit == null || this.dataToView.riskUnit == '' || this.dataToView.riskUnit == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        file: [{
          validator: (rule, value, callback) => {
            if (this.dataToView.file == null || this.dataToView.file == '' || this.dataToView.file == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
      },
      dataToView: {},
      model4: false,
      buttonLoading1: false,
      focusAspectList: [],
      options1: [],
      focusCycleList: [],
      rikDiscernList: [],
      loading: false,
      currentUser: JSON.parse(sessionStorage('userId').get('userId')),
      rikRankList: ["重大", "较大", "一般", "低"],
      switchFlag: false,
      tableHeight: '',
      rikRanks: [],
      loading1: false,
      form1: {
        hazardFactor: '',
        rikRankId: '',
      },
      pageSizeArray: [10, 20, 50, 100, 200],
      pagedata: {
        total: 0,
        pageSize: 10,
        currentPage: 1,
      },
      dataTable: [],
      ruleCustom: {
        riskUnit: [{
          validator: (rule, value, callback) => {
            if (this.InputData.saRiskInfo.riskUnit == null || this.InputData.saRiskInfo.riskUnit == '' || this.InputData.saRiskInfo.riskUnit == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        riskUnit2: [{
          validator: (rule, value, callback) => {
            if (this.InputData.saRiskInfo.riskUnit2 == null || this.InputData.saRiskInfo.riskUnit2 == '' || this.InputData.saRiskInfo.riskUnit2 == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        riskUnit3: [{
          validator: (rule, value, callback) => {
            if (this.InputData.saRiskInfo.riskUnit3 == null || this.InputData.saRiskInfo.riskUnit3 == '' || this.InputData.saRiskInfo.riskUnit3 == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        riskUnit4: [{
          validator: (rule, value, callback) => {
            if (this.InputData.saRiskInfo.riskUnit4 == null || this.InputData.saRiskInfo.riskUnit4 == '' || this.InputData.saRiskInfo.riskUnit4 == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        riskType: [{
          validator: (rule, value, callback) => {
            if (this.InputData.saRiskInfo.riskType == null || this.InputData.saRiskInfo.riskType == '' || this.InputData.saRiskInfo.riskType == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        rikDiscernName: [{
          validator: (rule, value, callback) => {
            if (this.InputData.saRiskInfo.rikDiscernName == null || this.InputData.saRiskInfo.rikDiscernName == '' || this.InputData.saRiskInfo.rikDiscernName == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        riskDesc: [{
          validator: (rule, value, callback) => {
            if (this.InputData.saRiskInfo.riskDesc == null || this.InputData.saRiskInfo.riskDesc == '' || this.InputData.saRiskInfo.riskDesc == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],

        q1: [{
          validator: (rule, value, callback) => {
            if (value == null || value == '' || value == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        q2: [{
          validator: (rule, value, callback) => {
            if (value == null || value == '' || value == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        m1: [{
          validator: (rule, value, callback) => {
            if (value == null || value == '' || value == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        m2: [{
          validator: (rule, value, callback) => {
            if (value == null || value == '' || value == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        e1: [{
          validator: (rule, value, callback) => {
            if (value == null || value == '' || value == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        s1: [{
          validator: (rule, value, callback) => {
            if (value == null || value == '' || value == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        s2: [{
          validator: (rule, value, callback) => {
            if (value == null || value == '' || value == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],

        manageMeasure: [{
          validator: (rule, value, callback) => {
            if (this.InputData.saRiskManage.manageMeasure == null || this.InputData.saRiskManage.manageMeasure == '' || this.InputData.saRiskManage.manageMeasure == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        emerMearsure: [{
          validator: (rule, value, callback) => {
            if (this.InputData.saRiskManage.emerMearsure == null || this.InputData.saRiskManage.emerMearsure == '' || this.InputData.saRiskManage.emerMearsure == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        dutyOrgName: [{
          validator: (rule, value, callback) => {
            if (this.InputData.saRiskManage.dutyOrgName == null || this.InputData.saRiskManage.dutyOrgName == '' || this.InputData.saRiskManage.dutyOrgName == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        dutyPersonName: [{
          validator: (rule, value, callback) => {
            if (this.InputData.saRiskManage.dutyOrgName == null || this.InputData.saRiskManage.dutyOrgName == '' || this.InputData.saRiskManage.dutyOrgName == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        focusAspectId: [{
          validator: (rule, value, callback) => {
            if (this.InputData.saRiskManage.focusAspectId == null || this.InputData.saRiskManage.focusAspectId == '' || this.InputData.saRiskManage.focusAspectId == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        focusCycleId: [{
          validator: (rule, value, callback) => {
            if (this.InputData.saRiskManage.focusCycleId == null || this.InputData.saRiskManage.focusCycleId == '' || this.InputData.saRiskManage.focusCycleId == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],

        checker: [{
          validator: (rule, value, callback) => {
            if (this.InputData.saRiskAssess.checker == null || this.InputData.saRiskAssess.checker == '' || this.InputData.saRiskAssess.checker == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
      },
      columns1: [
        {
          type: 'selection',
          width: 60, fixed: 'left',
          align: 'center'
        },
        {
          title: "序号",
          width: 80,
          align: "center",
          fixed: 'left',
          render: (h, params) => {
            return h('span', params.index + (this.pagedata.currentPage - 1) * this.pagedata.pageSize + 1);
          }
        },
        {
          title: "关注级别",
          width: 100,
          align: "center",
          fixed: 'left',
          render: (h, params) => {
            let str = '';
            if (params.row.saRiskInfo.rank == '1') {
              str = '集团'
            } else if (params.row.saRiskInfo.rank == '2') {
              str = '二级集团'
            } else if (params.row.saRiskInfo.rank == '3') {
              str = '集团和二级集团'
            }
            return h('span', str);
          }
        },
        /*   {
             title: '状态',
             align: 'center',
             fixed: 'left',
             key: 'status',
             width: 100,
             render: (h, params) => {
               let color = 'green';
               if (params.row.saRiskAssess.auditState == undefined || params.row.saRiskAssess.auditState == null || params.row.saRiskAssess.auditState == 3 || params.row.saRiskAssess.auditState == 0) {
                 color = 'red';
               }
               if (params.row.saRiskAssess.auditState == 1) {
                 color = 'blue';
               }
               return h('div', [
                 h('span', {
                   style: {
                     color: color
                   }
                 }, params.row.saRiskAssess.auditState == 1 ? '审批中' : params.row.saRiskAssess.auditState == 3 ? '审核驳回' : params.row.saRiskAssess.auditState == 2 ? '审批通过' : '未上报' || '--')
               ]);
             }
           },*/
        {
          width: 200,
          minWidth: 150,
          title: '一级风险单元',
          align: 'center',
          render: (h, params) => {
            return h('span', params.row.saRiskInfo.riskUnitName)
          }
        },
        {
          width: 200,
          minWidth: 150,
          title: '二级风险单元',
          align: 'center',
          render: (h, params) => {
            return h('span', params.row.saRiskInfo.riskUnit2)
          }
        },
        {
          width: 200,
          minWidth: 150,
          title: '三级风险单元',
          align: 'center',
          render: (h, params) => {
            return h('span', params.row.saRiskInfo.riskUnit3)
          }
        }, {
          width: 200,
          minWidth: 150,
          title: '四级风险单元',
          align: 'center',
          render: (h, params) => {
            return h('span', params.row.saRiskInfo.riskUnit4)
          }
        },
        {
          width: 150,
          title: '风险类别',
          align: 'center',
          key: 'riskTypeName',
          render: (h, params) => {
            return h('span', params.row.saRiskInfo.riskTypeName)
          }
        },
        {
          width: 150,
          title: '风险识别维度',
          align: 'center',
          key: 'rikDiscernName',
          render: (h, params) => {
            return h('span', params.row.saRiskInfo.rikDiscernName)
          }
        },
        {
          width: 150,
          title: '风险等级',
          align: 'center',
          key: 'rikRankName',
        },
        {
          width: 150,
          title: '风险警示色',
          align: 'center',
          key: 'rikColor',
          /* render: (h, params) => {
               // 需要延迟处理，否则颜色无法赋值
               setTimeout(() => {
                   let dom = document.getElementsByClassName(`${params.row.cellClassName.rikColor}`)
                   dom[0].style.backgroundColor = `${params.row.cellClassName.rikColor}`
               }, 100)
               return h('div', {
                   style: {
                       color: 'black'
                   }
               }, params.row.rikColor)
           }*/
        },
        {
          width: 150,
          title: '风险防范措施',
          align: 'center',
          key: 'manageMeasure',
          ellipsis: 'true',
          render: (h, params) => {
            return h('span', params.row.saRiskManage.manageMeasure)
          }
        },
        {
          width: 150,
          title: '应急措施',
          align: 'center',
          key: 'emerMearsure',
          ellipsis: 'true',
          render: (h, params) => {
            return h('span', params.row.saRiskManage.emerMearsure)
          }
        },
        {
          width: 150,
          title: '责任部门',
          align: 'center',
          key: 'dutyOrgName',
          render: (h, params) => {
            return h('span', params.row.saRiskManage.dutyOrgName)
          }
        },
        {
          width: 150,
          title: '责任人',
          align: 'center',
          key: 'dutyPersonName',
          render: (h, params) => {
            return h('span', params.row.saRiskManage.dutyPersonName)
          }
        },
        {
          title: '操作',
          key: 'action',
          fixed: 'right',
          width: 200,
          align: 'center',
          render: (h, params) => {
            return h('div', [
              h('A', {
                props: {
                  type: 'primary',
                  size: 'small'
                },
                style: {
                  fontSize: '14px',
                },
                on: {
                  click: () => {
                    this.InputData = params.row;
                    let recordeTime = new Date(params.row.saRiskManage.recordeTime)
                    this.InputData.saRiskManage.recordeTime = recordeTime.getFullYear() + '-' + (recordeTime.getMonth() + 1) + '-' + recordeTime.getDate()
                    this.model3 = true;
                  }
                }
              }, '详情'),
              h('Divider', {
                props: {
                  type: 'vertical',
                }
              }, ''),
              h('A', {
                props: {
                  type: 'primary',
                  size: 'small'
                },
                style: {
                  fontSize: '14px',
                  color: params.row._disabled ? '#d0d0d0' : '',
                  pointerEvents: params.row._disabled ? 'none' : ''
                },
                on: {
                  click: () => {
                    this.InputData = params.row;
                    let recordeTime = new Date(params.row.saRiskManage.recordeTime);
                    this.options1 = [];
                    this.options1.push({
                      userId: this.InputData.saRiskAssess.checker,
                      userName: this.InputData.saRiskAssess.checkerName,
                      orgInfo: {orgName: ''}
                    });
                    this.InputData.saRiskManage.recordeTime = recordeTime.getFullYear() + '-' + (recordeTime.getMonth() + 1) + '-' + recordeTime.getDate()
                    this.model1 = true;
                    this.add = false;
                  }
                }
              }, '修改'),
              h('Divider', {
                props: {
                  type: 'vertical',
                }
              }, ''),
              h('A', {
                props: {
                  type: 'error',
                  size: 'small'
                },
                style: {
                  fontSize: '14px',
                  color: params.row._disabled ? '#d0d0d0' : 'red',
                  pointerEvents: params.row._disabled ? 'none' : ''
                },
                on: {
                  click: () => {
                    this.deleteData(params.row);
                  }
                }
              }, '删除')
            ]);
          }
        }
      ],
      add: false,
      model1: false,
      model3: false,
      rootOrgId: sessionStorage('userId').getObject('userId').orgInfo.orgId,
      InputData: {
        saRiskInfo: {},
        saRiskAssess: {},
        saRiskManage: {}
      },
      q1List: [
        {
          id: 1,
          q1Name: '基本不可能(过去从未发生)',
          q2Name: '承受力很强',
          m1Name: '小(0人)',
          m2Name: '很小(小于等于2人)',
          e1Name: '很小(小于10万元)',
          s1Name: '很小(影响小于10人)',
          s2Name: '很小(本区关注1(含)天至7天或本市关注1天内)',
        },
        {
          id: 2,
          q1Name: '较不可能(过去10年以上发生1次)',
          q2Name: '承受力强',
          m2Name: '小(3至4人)',
          e1Name: '小(10万元至50万元)',
          s1Name: '小(影响在10至99人之间)',
          s2Name: '小(本区关注7(含)天至30天或本市关注1(含)天至7天或国内关注1天内)',
        },
        {
          id: 3,
          q1Name: '可能(过去10年发生1次)',
          q2Name: '承受力一般',
          m1Name: '一般(1至2人)',
          m2Name: '一般(5至15人)',
          e1Name: '一般(50万元至100万元)',
          s1Name: '一般(影响在100至499人之间)',
          s2Name: '一般(本区关注30(含)天以上或本市关注7(含)天至30天或国内关注1(含)天至7天或国际关注1天内)',
        },
        {
          id: 4,
          q1Name: '较可能(过去5年发生1次)',
          q2Name: '承受力弱',
          m1Name: '大(3至9人)',
          m2Name: '大(16至49人)',
          e1Name: '大(100万元至500万元)',
          s1Name: '大(影响在500至999人之间)',
          s2Name: '大(本市关注30(含)天以上或国内关注7(含)天至30天或国际关注1(含)天至7天)',
        },
        {
          id: 5,
          q1Name: '很可能(过去2年发生1次以上)',
          q2Name: '承受力很弱',
          m1Name: '很大(大于等于10人)',
          m2Name: '很大(大于等于50人)',
          e1Name: '很大(大于等于500万元)',
          s1Name: '很大(影响大于等于1000人)',
          s2Name: '很大(国内关注30(含)天以上或国际关注7(含)天以上)',
        }
      ],
      riskTypeArr: [],
      buttonLoading: false,

      model2: false,
      riskPreset: [],
      columns2: [
        {
          type: 'index',
          title: '序号',
          fixed: 'left',
          width: 100,
          align: 'center',
        }, {
          width: 200,
          minWidth: 150,
          title: '一级风险单元',
          align: 'center',
          render: (h, params) => {
            return h('span', params.row.saRiskInfo.riskUnitName)
          }
        },
        {
          width: 200,
          minWidth: 150,
          title: '二级风险单元',
          align: 'center',
          render: (h, params) => {
            return h('span', params.row.saRiskInfo.riskUnit2)
          }
        },
        {
          width: 200,
          minWidth: 150,
          title: '三级风险单元',
          align: 'center',
          render: (h, params) => {
            return h('span', params.row.saRiskInfo.riskUnit3)
          }
        }, {
          width: 200,
          minWidth: 150,
          title: '四级风险单元',
          align: 'center',
          render: (h, params) => {
            return h('span', params.row.saRiskInfo.riskUnit4)
          }
        }, {
          width: 150,
          title: '风险类别',
          align: 'center',
          key: 'riskTypeName',
          render: (h, params) => {
            return h('span', params.row.saRiskInfo.riskTypeName)
          }
        }, {
          width: 150,
          title: '风险识别维度',
          align: 'center',
          key: 'rikDiscernName',
          render: (h, params) => {
            return h('span', params.row.saRiskInfo.rikDiscernName)
          }
        }, {
          width: 150,
          title: '风险等级',
          align: 'center',
          key: 'rikRankName',
        }, {
          width: 150,
          title: '风险警示色',
          align: 'center',
          key: 'rikColor',
          /* render: (h, params) => {
               // 需要延迟处理，否则颜色无法赋值
               setTimeout(() => {
                   let dom = document.getElementsByClassName(`${params.row.cellClassName.rikColor}`)
                   dom[0].style.backgroundColor = `${params.row.cellClassName.rikColor}`
               }, 100)
               return h('div', {
                   style: {
                       color: 'black'
                   }
               }, params.row.rikColor)
           }*/
        }, {
          width: 150,
          title: '风险防范措施',
          align: 'center',
          key: 'manageMeasure',
          ellipsis: 'true',
          render: (h, params) => {
            return h('span', params.row.saRiskManage.manageMeasure)
          }
        }, {
          width: 150,
          title: '应急措施',
          align: 'center',
          ellipsis: 'true',
          key: 'emerMearsure',
          render: (h, params) => {
            return h('span', params.row.saRiskManage.emerMearsure)
          }
        }, {
          width: 150,
          title: '责任部门',
          align: 'center',
          key: 'dutyOrgName',
          render: (h, params) => {
            return h('span', params.row.saRiskManage.dutyOrgName)
          }
        }, {
          width: 150,
          title: '责任人',
          align: 'center',
          key: 'dutyPersonName',
          render: (h, params) => {
            return h('span', params.row.saRiskManage.dutyPersonName)
          }
        }
      ],
      pageModel2: {
        total: 0,
        pageSize: 10,
        currentPage: 1,
        hazardFactor: '',
        rikRankId: '',
      },

      reportSelectAll: [],
      riskUnits: [],
      riskUnit2s: [],
      riskUnit3s: [],
      riskUnit4s: [],
    }
  },
  computed: {
    passibleCal: function () {
      let r5 = 0 //可能性计算
      let s5 = 0 //严重性计算
      let rikRan = ' '
      let rikColor = ' '
      if (this.InputData.q1 > 0 && this.InputData.q2 > 0) {
        r5 = Math.ceil(this.NumberAdd(this.InputData.q1, this.InputData.q2) / 2)
      }
      if (this.InputData.m1 > 0 && this.InputData.m2 > 0 && this.InputData.e1 > 0 && this.InputData.s1 > 0 && this.InputData.s2 > 0) {
        s5 = Math.ceil((this.InputData.m1 + this.InputData.m2 + this.InputData.e1 + this.InputData.s1 + this.InputData.s2) / 5)
      }
      this.InputData.severityCal = s5 > 0 ? s5 : ' ';
      this.InputData.severityVal = s5 > 0 ? s5 : ' ';

      this.InputData.passibleCal = r5 > 0 ? r5 : ' ';
      this.InputData.passibleVal = r5 > 0 ? r5 : ' ';
      if (s5 == 0 || r5 == 0) {
        rikRan = ' '
      } else if ((r5 > 2 && s5 == 5) || (r5 == 5 && s5 == 4)) {
        rikRan = '重大'
      } else if ((r5 == 2 && s5 == 5) || ((r5 == 3 || r5 == 4) && s5 == 4) || (r5 > 3 && s5 == 3) || (s5 == 2 && r5 == 5)) {
        rikRan = '较大'
      } else if ((r5 == 1 && s5 > 3) || ((s5 == 3 || s5 == 4) && r5 == 2) || ((s5 == 2 || s5 == 3) && r5 == 3) || (s5 == 2 && r5 == 4) || (s5 == 1 && r5 > 3)) {
        rikRan = '一般'
      } else {
        rikRan = '低'
      }
      rikColor = rikRan == '重大' ? '红' : rikRan == '较大' ? '橙' : rikRan == '一般' ? '黄' : rikRan == '低' ? '蓝' : ' '
      this.InputData.rikRankName = rikRan;
      this.InputData.rikColor = rikColor
      this.InputData.saRiskAssess.rikColor = rikColor
      return this.InputData.passibleCal;
    }
  },
  watch: {
    "model4": function (qw, er) {
      if (qw && this.model4) {
        setTimeout(() => {
          this.$refs.trainOrg.setCurrentOrg();

        }, 100)
      } else {
        this.$refs.trainOrg.setCurrentOrg();

      }
    },
    "model1": function (qw, er) {
      if (qw && this.model1) {
        setTimeout(() => {
          this.$refs.riskUnit.setCurrentOrg();
          this.$refs.childOrg.setCurrentOrg();
          this.$refs.childUser.setCurrentOrg();
          this.$refs.childUser1.setCurrentOrg();
        }, 100);
      } else {
        this.$refs.riskUnit.resetCurrentOrg();
        this.$refs.childOrg.resetCurrentOrg();
        this.$refs.childUser.resetCurrentOrg();
        this.$refs.childUser1.resetCurrentOrg();
      }
      this.openChange()
    },
  },
  mounted() {
    this.tableHeight = window.innerHeight - 325
    //this.$refs.table.$el.offsetTop - 220;
    this.query()
    // this.query1()
  },
  methods: {
    hasRole,
    rank(type) {

      let data = {
        type: type,
        ids: this.reportSelectAll.map(item => item.saRiskInfo.riskId),
      }
      this.$http.post(Api.riskInfoRank, data).then(r => {
        if (r.data.status == '200') {
          this.$Message.success("操作成功")
          this.query();
        } else {
          this.$Message.error(r.data.msg);
        }
      })

    },
    batchDelete() {
      this.$Modal.confirm({
        title: '提示',
        content: '<p>确定删除选中数据？</p>',
        onOk: () => {
          this.deleteButton = true
          let ids = {
            info: [],
            assess: [],
            risk: [],
            manage: []
          }
          this.reportSelectAll.forEach(item => {
            ids.info.push(item.saRiskInfo.riskId)
            ids.assess.push(item.saRiskAssess.assessId)
            ids.risk.push(item.envId)
            ids.manage.push(item.saRiskManage.manageId)
          })
          let url = Api.batchDeleteRiskEnv;
          this.$http.post(url, ids).then((res) => {
            this.$Message.success('成功');
            this.query()
            this.reportSelectAll = []
            this.deleteButton = false
          }).catch(e => {
            this.deleteButton = false
            this.$Message.error("删除异常")
          })
        },
        onCancel: () => {
        }
      });
    },
    downloadMod() {
      let link = document.createElement('a');
      link.style.display = 'none';
      link.href = Api.downloadModRiskEnv;
      document.body.appendChild(link);
      link.click();
      document.body.removeChild(link)
    },
    beforeUpload(file) {
      this.$set(this.dataToView, "file", file);
      return false;
    },
    uploadSubmit(name) {
      let _this = this;
      this.$refs[name].validate((valid) => {
        if (valid) {
          _this.uploadButton = true;
          let formData = new FormData();
          formData.append("file", _this.dataToView.file); // 文件对象
          let url = Api.uploadRiskEnv + _this.dataToView.riskUnit
          this.$http.post(url, formData).then((res) => {
            if (res.data.status == "200") {
              this.$Message.info("导入成功")
              _this.model4 = false;
              _this.query();
            } else {
              this.$Message.error(res.data.msg)
            }
            _this.uploadButton = false;
          }).catch(e => {
            this.$Message.error("导入失败")
            console.log(e)
            _this.uploadButton = false;
          })
        } else {
          this.$Message.error('请填报完整!');
        }
      });
    },
    uploadcancel() {
      this.model4 = false;
    },
    uploadExcel() {
      this.dataToView = {};
      this.model4 = true;
    },
    downloadExcel() {

    },
    setRiskUnitId(data) {
      this.dataToView.riskUnit = data[data.length - 1];
    },
    setRiskUnitNames(data) {
      this.dataToView.riskUnitName = data;
    },

    focusAspectChange(e) {
      this.InputData.saRiskManage.focusAspectId = e.value;
      this.InputData.saRiskManage.focusAspect = e.label;
    },
    focusCycleChange(e) {
      this.InputData.saRiskManage.focusCycleId = e.value;
      this.InputData.saRiskManage.focusCycle = e.label;
    },
    remoteMethod1(query) {
      if (query !== '') {
        clearTimeout(this.remoteMethod1.timer);
        this.remoteMethod1.timer = setTimeout(() => {
          this.options1.splice(0, this.options1.length);
          this.loading1 = true;
          let data = {
            userName: query,
            orgId: sessionStorage('userId').getObject('userId').orgInfo.parentId
          };
          this.$http.get(Api.queryUserByUserName, {params: data}).then((res) => {
            this.loading1 = false;
            res.data.data.forEach(item => {
              this.options1.push(item);
            })

          }).catch(e => {
            this.loading1 = false;
          })
        }, 200);
      } else {
        this.options1 = [];
      }
    },
    switchQuery(flag) {
      this.switchFlag = flag;
      if (!this.switchFlag) {
        this.tableHeight = this.tableHeight + 88;
      } else {
        this.tableHeight = this.tableHeight - 88;
      }
    },
    query1() {
      let url = Api.riskUnitsList + '/' + sessionStorage('userId').getObject('userId').orgInfo.orgId
      this.$http.get(url).then((res) => {
        this.riskUnitsAll = res.data.data;
      }).catch(e => {
        this.$Message.error("数据获取失败")
      })
    },
    querys() {
      this.pagedata.currentPage = 1;
      this.query();
    },
    openChange() {
      this.riskUnitsAll.forEach(item => {
        this.riskUnits.push(item.riskUnit)
        this.riskUnits = [...new Set(this.riskUnits)].filter(function (s) {
          return s && s.trim(); // 注：IE9(不包含IE9)以下的版本没有trim()方法
        })
        if (item.riskUnit == this.InputData.saRiskInfo.riskUnit) {
          this.riskUnit2s.push(item.riskUnit2)
          this.riskUnit2s = [...new Set(this.riskUnit2s)].filter(function (s) {
            return s && s.trim(); // 注：IE9(不包含IE9)以下的版本没有trim()方法
          })
        }
        if (item.riskUnit2 == this.InputData.saRiskInfo.riskUnit2) {
          this.riskUnit3s.push(item.riskUnit3)
          this.riskUnit3s = [...new Set(this.riskUnit3s)].filter(function (s) {
            return s && s.trim(); // 注：IE9(不包含IE9)以下的版本没有trim()方法
          })
        }
        if (item.riskUnit3 == this.InputData.saRiskInfo.riskUnit3) {
          this.riskUnit4s.push(item.riskUnit4)
          this.riskUnit4s = [...new Set(this.riskUnit4s)].filter(function (s) {
            return s && s.trim(); // 注：IE9(不包含IE9)以下的版本没有trim()方法
          })
        }
      })
    },
    rikDiscernChange(appStatus) {
      this.InputData.saRiskInfo.rikDiscernId = appStatus.value;
      this.InputData.saRiskInfo.rikDiscernName = appStatus.label;
    },
    riskUnitAdd(val) {
      this.riskUnits.push(val)
      this.riskUnit2s = []
    },
    riskUnit2Add(val) {
      this.riskUnit2s.push(val);
      this.riskUnit3s = []
    },
    riskUnit3Add(val) {
      this.riskUnit3s.push(val);
      this.riskUnit4s = []
    },
    riskUnit4Add(val) {
      this.riskUnit4s.push(val);
    },

    reporting() {
      this.$Modal.confirm({
        title: '提示',
        content: '<p>确定上报该数据？</p>',
        onOk: () => {
          this.buttonLoading = true
          let assessIds = []
          this.reportSelectAll.forEach(item => {
            assessIds.push(item.assessId)
          })
          let url = Api.riskReport + "/" + sessionStorage('userId').getObject('userId').userId;
          this.$http.post(url, assessIds).then((res) => {
            this.$Message.success('成功');
            this.query()
            this.reportSelectAll = []
            this.buttonLoading = false
          }).catch(e => {
            this.$Message.error("上报异常")
          })
        },
        onCancel: () => {
        }
      });
    },
    reportSelect(select) {
      this.reportSelectAll = select
      console.log(select)
    },
    addByTemp() {
      this.loading = true;
      let rikRankId = ''
      for (let i = 0; i < this.rikRanks.length; i++) {
        rikRankId += this.rikRanks[i] + ",";
      }
      let data = {
        startPage: this.pageModel2.currentPage,
        size: this.pageModel2.pageSize,
        preset: '0',
        orgId: sessionStorage('userId').getObject('userId').companyId,
        hazardFactor: this.pageModel2.hazardFactor,
        rikRankId: rikRankId
      }
      data = Object.assign(data);
      let url = Api.environmentalRiskList
      this.$http.get(url, {params: data}).then((res) => {
        res.data.data.data.forEach(item => {
          const sty = item.rikColor == '红' ? 'table-info-cell-red' : item.rikColor == '橙' ? 'table-info-cell-orage' : item.rikColor == '黄' ? 'table-info-cell-yellow' : item.rikColor == '蓝' ? 'table-info-cell-blue' : ''
          item.cellClassName = {rikColor: sty}
        })
        this.riskPreset = res.data.data.data;
        this.pageModel2.total = res.data.data.totalSize;
        this.loading = false;
      }).catch(e => {
        this.$Message.error("数据获取失败")
      })
      this.model2 = true
    },
    danxuan(row, index) {
      this.add = true;
      let recordeTime = new Date(row.saRiskManage.recordeTime)
      row.saRiskManage.recordeTime = recordeTime.getFullYear() + '-' + (recordeTime.getMonth() + 1) + '-' + recordeTime.getDate()
      row.saRiskInfo.riskId = ''
      this.InputData = row
      this.model2 = false
      this.model1 = true
    },
    pageChange1(pageNum) {
      this.pageModel2.currentPage = pageNum;
      this.addByTemp();
    },
    pageSizeChange1(pageSize) {
      this.pageModel2.pageSize = pageSize;
      this.addByTemp();
    },

    changeSelect(appStatus) {
      this.InputData.saRiskInfo.riskType = appStatus.value;
      this.InputData.saRiskInfo.riskTypeName = appStatus.label;
    },

    setOrgId(data) {
      this.InputData.saRiskManage.dutyOrgId = data[data.length - 1];
    },
    setOrgName(data) {
      this.InputData.saRiskManage.dutyOrgName = data;
    },
    setRiskUnit(data) {
      this.InputData.saRiskInfo.riskUnit = data[data.length - 1];
    },
    setRiskUnitName(data) {
      this.InputData.saRiskInfo.riskUnitName = data;
    },
    setUserName(data) {
      this.InputData.saRiskManage.dutyPersonName = data;
    },
    setUserId(data) {
      this.InputData.saRiskManage.dutyPersonId = data[data.length - 1];
    },
    setUserName1(data) {
      this.InputData.saRiskAssess.checkerName = data;
    },
    setUserId1(data) {
      this.InputData.saRiskAssess.checker = data[data.length - 1];
    },

    onCancel() {
      this.InputData = {
        saRiskInfo: {},
        saRiskAssess: {},
        saRiskManage: {}
      }
      this.model1 = false
      this.query()
    },
    submit(name) {
      this.$refs[name].validate((valid) => {
        if (valid) {
          this.buttonLoading = true
          this.InputData.saRiskManage.recordeTime = new Date(this.InputData.saRiskManage.recordeTime)
          let orgId = sessionStorage('userId').getObject('userId').orgInfo.orgId
          let userId = sessionStorage('userId').getObject('userId').userId
          let url = ''
          if (this.add) {
            url = Api.environmentalRiskAdd
            this.InputData.bsflag = '0'
            this.InputData.saRiskAssess.preset = '1'//0是预置  1不是预置
            this.InputData.createOrgId = orgId
            this.InputData.createUserId = userId
            this.InputData.saRiskInfo.createOrgId = orgId
            this.InputData.saRiskInfo.createUserId = userId
            this.InputData.saRiskAssess.createOrgId = orgId
            this.InputData.saRiskAssess.createUserId = userId
            this.InputData.saRiskManage.createOrgId = orgId
            this.InputData.saRiskManage.createUserId = userId
            this.$http.post(url, this.InputData).then((res) => {
              this.$Message.success('成功');
              this.query()
              this.buttonLoading = false
            }).catch(e => {
              this.$Message.error('请求失败');
            })
            this.model1 = false
          } else {
            url = Api.environmentalRiskUpdate;
            this.InputData.updateUserId = userId
            this.InputData.updateOrgId = orgId
            this.InputData.saRiskInfo.updateUserId = userId
            this.InputData.saRiskInfo.updateOrgId = orgId
            this.InputData.saRiskAssess.updateUserId = userId
            this.InputData.saRiskAssess.updateOrgId = orgId
            this.InputData.saRiskManage.updateUserId = userId
            this.InputData.saRiskManage.updateOrgId = orgId
            this.$http.post(url, this.InputData).then((res) => {
              this.$Message.success('成功');
              this.buttonLoading = false
              this.query()
            }).catch(e => {
              this.$Message.error('请求失败');
            })
            this.model1 = false
          }
        } else {
          this.$Message.error('失败!');
        }
      })

    },

    deleteData(row) {

      this.$Modal.confirm({
        title: '提示',
        content: '<p>确认删除此行数据？</p>',
        onOk: () => {
          let url = Api.environmentalRiskDelete + '/' + row.envId
          this.$http.delete(url).then((res) => {
            this.$Message.success('成功');
            this.query()
          }).catch(e => {
            this.$Message.error("数据获取失败")
          })
        },
        onCancel: () => {
        }
      });

    },
    addInfo() {
      this.add = true;
      this.riskUnits = [];
      this.riskUnit2s = [];
      this.riskUnit3s = [];
      this.riskUnit4s = [];
      this.InputData = {
        saRiskInfo: {},
        saRiskAssess: {},
        saRiskManage: {
          recorder: sessionStorage('userId').getObject('userId').userName,
          recordeTime: new Date().getFullYear() + '-' + (new Date().getMonth() + 1) + '-' + new Date().getDate()
        }
      };
      this.model1 = true;
    },
    query() {
      this.form1.rikRankId = "";
      let data = {
        startPage: this.pagedata.currentPage,
        size: this.pagedata.pageSize
      }
      this.form1.orgId = sessionStorage('userId').getObject('userId').companyName
      this.form1.preset = '1'
      for (let i = 0; i < this.rikRanks.length; i++) {
        this.form1.rikRankId += this.rikRanks[i] + ",";

      }
      data = Object.assign(data, JSON.parse(JSON.stringify(this.form1)));
      let url = Api.environmentalRiskList
      this.loading = true;
      this.$http.get(url, {params: data}).then((res) => {
        res.data.data.data.forEach(item => {
          const sty = item.rikColor == '红' ? 'table-info-cell-red' : item.rikColor == '橙' ? 'table-info-cell-orage' : item.rikColor == '黄' ? 'table-info-cell-yellow' : item.rikColor == '蓝' ? 'table-info-cell-blue' : ''
          item.cellClassName = {rikColor: sty}
        })
        this.dataTable = res.data.data.data;
        this.pagedata.total = res.data.data.totalSize;

        this.loading = false;
      }).catch(e => {
        this.$Message.error("数据获取失败")
        this.loading = false;
      })
      // this.query1()
      let _this = this
      this.gDic(Api.queryCodeDetailBySortId + "/risk-10009", function (result) {
        _this.riskTypeArr = result;
      });
      this.gDic(Api.queryCodeDetailBySortId + "/risk-10013", function (result) {
        _this.rikDiscernList = result;
      });
      this.gDic(Api.queryCodeDetailBySortId + "/risk-10014", function (result) {
        _this.focusCycleList = result;
      });
      this.gDic(Api.queryCodeDetailBySortId + "/risk-10015", function (result) {
        _this.focusAspectList = result;
      });
    },
    reset(type) {
      this.form1 = {};
      this.rikRanks = [];
      this.pageModel2 = {
        hazardFactor: '',
      }
      if (type == 1) {
        this.pageModel2.currentPage = 1
        this.addByTemp()
      } else {
        this.pagedata.currentPage = 1
        this.querys()
      }
    },
    pageChange(pageNum) {
      this.pagedata.currentPage = pageNum;
      this.query();
    },
    pageSizeChange(pageSize) {
      this.pagedata.pageSize = pageSize;
      this.query();
    },
  }
}
</script>

<style scoped>
@import '../../../../index.css';

.hint > p {
  color: red;
}
</style>
